﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>新增短信</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <link href="../JS/Date/FT_Date.min.css" rel="stylesheet" />
    <script src="../JS/layer/layer.m.js"></script>
    <style type="text/css">
        .ui-select {
            border: none;
            border: 0;
            background-color: #fff;
            appearance: none;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
        }

        .ms-controller, [ms-controller] {
            display: none;
        }
    </style>
</head>
<body ms-controller="dxmodel">
    <div id="content">
        <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
            <button class="ui-btn-lg" onclick="back()">
                取消
            </button>
            <button class="ui-btn-lg ui-btn-primary" id="save" ms-click="savedata()">
                新增短信
            </button>
        </div>
        <section class="ui-container">
            <div class="ui-form">
                <div class="ui-form-item ui-border-b " style="height:auto;min-height:44px">
                    <label>
                        接收号码
                    </label>
                    <!--<input type="tel" placeholder="请输入接收号码" ms-duplex="ctData.dxnums" />-->
                    <div class="ui-txt-muted ui-whitespace" style="padding-left: 95px; text-align: justify; overflow: hidden; word-wrap: break-word;" id="jshm" ms-click="hmbjk()">请输入接收号码</div>
                </div>
                <div class="ui-form-item ui-border-b ui-btn-group" style="height:auto;min-height:44px">
                    <button class="ui-btn-lg ui-btn-primary" ms-click="selperson()" style="height:30px;line-height:30px;">
                        员工号码
                    </button>
                    <button class="ui-btn-lg ui-btn-primary" ms-click="selkhperson()" style="height: 30px; line-height: 30px; ">
                        客户号码
                    </button>
                </div>
                <div class="ui-form-item ui-border-b ui-form-item-textarea" style="height:auto;min-height:44px">
                    <label>
                        短信内容
                    </label>
                    <textarea placeholder="请输入短信内容" style="height:80px;" class="chackTextarea-area" ms-duplex="ctData.dxContent"></textarea>
                    <!--<div class="ui-txt-muted ui-whitespace" style="padding-left: 95px;text-align:justify" id="hdjj" ms-click="bjk()">请输入短信内容</div>-->
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        立即发送
                    </label>
                    <label class="ui-switch" style="padding-left: 95px;right:auto">
                        <input type="checkbox" ms-duplex-radio="isfs" />
                    </label>
                </div>
                <div class="ui-form-item ui-border-b" ms-if="!isfs">
                    <label>
                        发送时间
                    </label>
                    <div class="ui-select ui-border-b">
                        <input type="text" placeholder="2015-07-10" id="appSDate" ms-duplex="ctData.SendTime" style="padding-left:0" />
                    </div>
                </div>

            </div>
        </section>
    </div>
    <iframe id="iframep" src="UI_PERSON.html" style="display: none; margin-bottom: -7px;" frameborder="0"></iframe>
    <iframe id="iframek" src="UI_PERSON_KH.html" style="display: none; margin-bottom: -7px;" frameborder="0"></iframe>

    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/avalon.mobile.min.js"></script>
    <script src="../JS/MobileCom.js?v=1.1"></script>

    <script src="../JS/mobiscroll.zepto.js"></script>
    <script src="../JS/mobiscroll.core.js"></script>
    <script src="../JS/mobiscroll.scroller.js"></script>
    <script src="../JS/mobiscroll.datetime.js"></script>
    <script src="../JS/mobiscroll.i18n.zh.js"></script>
    <script src="../JS/jquery.autoTextarea.js"></script>
    <script>
        var currYear = (new Date()).getFullYear();
        var opt = {
            date: { preset: 'datetime' },
            defaultopi: {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                lang: 'zh',
                startYear: currYear - 5, //开始年份
                endYear: currYear + 5, //结束年份
                onSelect: function (valueText, inst) {
                    //model.ctData.RBDate = valueText;
                }
            }
        };
        function fun(str) {
            $("#appSDate").scroller($.extend(opt['date'], opt['defaultopi'])).scroller('setDate', str, true);
        }

        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            //隐藏右上角按钮
            WeixinJSBridge.call('hideOptionMenu');
        });

        var width = 0;
        var height = 0;
        var model = avalon.define({
            $id: "dxmodel",
            isfs: true,
            ctData: { "dxnums": "", "dxContent": "", "SendTime": ""},
            savedata: function () {
                if (model.ctData.dxnums == "") {
                    $.tips({
                        content: "请输入接收号码",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                //else {
                //    var reg = /^(?:13\d|14\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/;
                //    if (!reg.test(model.ctData.dxnums)) {
                //        $.tips({
                //            content: "接收号码格式错误",
                //            stayTime: 2000,
                //            type: "warn"
                //        })
                //        return;
                //    }
                //}
                if (model.ctData.dxContent == "") {
                    $.tips({
                        content: "请输入短信内容",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }

                var lg = $.loading({
                    content: '保存中...',
                })
                if (model.isfs)
                {
                    model.ctData.SendTime = "";
                }
                
                $.post("/API/WXAPI.ashx?Action=ADDDXGL&r=" + Math.random(), { "P1": JSON.stringify(model.ctData.$model) }, function (data) {
                    lg.hide();
                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        $("button").hide();
                        var el = $.tips({
                            content: "保存成功！",
                            stayTime: 2000,
                            type: "success"
                        })
                        el.on("tips:hide", function () {

                            window.location.replace(location.href);

                        })
                    }
                    else {
                        $.tips({
                            content: "保存失败，原因：" + data.ErrorMsg,
                            stayTime: 2000,
                            type: "warn"
                        })
                    }
                })
            },
            bjk: function () {

                var tc = layer.open({
                    type: 1,
                    //content:$("#bmxx").html(),
                    //title: "活动简介",
                    content: '<div class="ui-form-item ui-form-item-textarea ui-border-b" style="width:' + (width - 76) + 'px;height:200px"><textarea id="hdjjbjk" style="padding-left: 0;height:170px;border: 1px solid #e0e0e0;" placeholder="请输入短信内容">' + model.ctData.dxContent + '</textarea></div>',
                    btn: ['确认', '取消'],
                    shadeClose: false,
                    yes: function () {
                        model.ctData.dxContent = $("#hdjjbjk").val();
                        if ($("#hdjjbjk").val() != "") {
                            $("#hdjj").removeClass("ui-txt-muted");
                            $("#hdjj").html($("#hdjjbjk").val());
                        }
                        else {
                            $("#hdjj").addClass("ui-txt-muted");
                            $("#hdjj").html("请输入短信内容");
                        }

                        layer.close(tc);

                    }, no: function () {
                    }
                })
                $("#hdjjbjk").focus();
            },
            hmbjk: function () {

                var tc = layer.open({
                    type: 1,
                    //content:$("#bmxx").html(),
                    //title: "活动简介",
                    content: '<div class="ui-form-item ui-form-item-textarea ui-border-b" style="width:' + (width - 76) + 'px;height:200px"><textarea id="hdjjbjk" style="padding-left: 0;height:170px;border: 1px solid #e0e0e0;" placeholder="请输入接收号码，多个号码用‘,’隔开">' + model.ctData.dxnums + '</textarea></div>',
                    btn: ['确认', '取消'],
                    shadeClose: false,
                    yes: function () {
                        model.ctData.dxnums = $("#hdjjbjk").val();
                        if ($("#hdjjbjk").val() != "") {
                            $("#jshm").removeClass("ui-txt-muted");
                            $("#jshm").html($("#hdjjbjk").val());
                        }
                        else {
                            $("#jshm").addClass("ui-txt-muted");
                            $("#jshm").html("请输入接收号码");
                        }

                        layer.close(tc);

                    }, no: function () {
                    }
                })
                $("#hdjjbjk").focus();
            },
            repshow: function () {
                $(this).parent().siblings().removeClass("active");
                $(this).parent().addClass("active");
            },
            selperson: function () {
                $("#content").hide();
                $("#iframep").show();

                var cheight = height;
                var cwidth = document.documentElement.clientWidth;

                $("#iframep").css("height", cheight);
                $("#iframep").css("width", cwidth);

            },
            selkhperson: function () {
                $("#content").hide();
                $("#iframek").show();

                var cheight = height;
                var cwidth = document.documentElement.clientWidth;

                $("#iframek").css("height", cheight);
                $("#iframek").css("width", cwidth);
            }

        });

        avalon.ready(function () {
            height = document.documentElement.clientHeight;
            width = document.documentElement.clientWidth;
            fun(new Date());
            model.ctData.SendTime = $("#appSDate").val();
            $(".chackTextarea-area").autoTextarea({
                maxHeight: 220,
                minHeight: 80
            });
        })

        function goback() {
            $("#content").show();
            $("#iframep").hide();
            $("#iframek").hide();
        }
        function goconfirm(json) {
            //if (model.ctData.dxnums) {
            //    var str = model.ctData.dxnums;
            //    if (str.substring(str.length - 1, 1) == ",") {
            //        model.ctData.dxnums = str + json.vuserphone;
            //    } else {
            //        model.ctData.dxnums = str + "," + json.vuserphone;
            //    }
            //}
            //else {
            //    model.ctData.dxnums = json.vuserphone;
            //}
            model.ctData.dxnums = json.vuserphone;
            if (json.vuserphone != "") {
                $("#jshm").removeClass("ui-txt-muted");
                $("#jshm").html(model.ctData.dxnums);
            }
            else {
                $("#jshm").addClass("ui-txt-muted");
                $("#jshm").html("请输入接收号码");
            }

            $("#content").show();
            $("#iframep").hide();
            $("#iframek").hide();
        }
        function back() {
            window.location.replace("UI_DXGL_LIST.html?r=" + Math.random());
        }
    </script>

</body>
</html>
